<?php

require_once '../simpletest/autorun.php';
require_once '../simpletest/web_tester.php';
require_once '../../src/useragent/UserAgentFactory.php';

/**
 * <b>XUCBrowserUserAgent简介:</b>
 * <p>XUCBrowserUserAgent单元测试</p>
 *
 * @author cairq@ucweb.com
 */
class XUCBrowserUserAgentTest extends WebTestCase {
    function testXUCBrowserUserAgent() {
      //兼容性测试
        $userAgent = "";
        $ua = UserAgentFactory::createXUCBrowserUserAgent($userAgent);
        
        $this->assertTrue($ua->isUnkown()); 
        $this->assertTrue($ua->isEmpty()); 
        
        //兼容性测试
        $userAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.0; en; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7";
        $ua = UserAgentFactory::createXUCBrowserUserAgent($userAgent);
        
        $this->assertTrue($ua->isUnkown()); 
        $this->assertEqual($ua->getxUCBrowserUserAgent(), $userAgent);

        //兼容性测试
        $userAgent = "hello, world!";
        $ua = UserAgentFactory::createXUCBrowserUserAgent($userAgent);
        
        $this->assertTrue($ua->isUnkown()); 
        $this->assertEqual($ua->getxUCBrowserUserAgent(), $userAgent);
        
        //兼容性测试, 兼容旧有平台的UA处理
        $userAgent = "NOKIA E71 RM-346/UCWEB6.7.1.1/28/999";
        $ua = UserAgentFactory::createXUCBrowserUserAgent($userAgent); 
    
        $this->assertTrue($ua->isUnkown()); 
        $this->assertEqual($ua->getxUCBrowserUserAgent(), $userAgent);
        
        //正确的UA测试
        $userAgent = "pf(Java);er(U);la(zh-CN);up(U2/1.0.0);re(U2/1.0.0);dv(Nokia6300);pr(UCBrowser/8.6.0.199);ov(S40 V3);pi(320*240);de(320*240);pm(1);bv(1);nm(0);im(1);sr(2);";
        $ua = UserAgentFactory::createXUCBrowserUserAgent($userAgent);
        
        // User-Agent Test
        $this->assertEqual($ua->getDevice(), "Nokia6300");
        $this->assertEqual($ua->getPlatform(), "Java");
        $this->assertEqual($ua->getOs(), "S40");
        $this->assertEqual($ua->getOsVersion(), "V3");
        $this->assertEqual($ua->getLanguage(), "zh-CN");
        $this->assertEqual($ua->getProduct(), "UCBrowser");
        $this->assertEqual($ua->getProductVersion(), "8.6.0.199");
        $this->assertEqual($ua->getRenderingEngine(), "U2");
        $this->assertEqual($ua->getRenderingEngineVersion(), "1.0.0");
        $this->assertEqual($ua->getUcPlatform(), "U2");
        $this->assertEqual($ua->getUcPlatformVersion(), "1.0.0");
        
        $this->assertTrue($ua->isJava());
        $this->assertTrue($ua->isSafe());
        $this->assertTrue($ua->isU2());
        $this->assertFalse($ua->isMobileMode());
        $this->assertFalse($ua->isU3());
        $this->assertFalse($ua->isUnkown()); 
        $this->assertFalse($ua->isEmpty()); 
        $this->assertFalse($ua->isAndroid());
        $this->assertFalse($ua->isApad());
        $this->assertFalse($ua->isBrew());
        $this->assertFalse($ua->isEmpty());
        $this->assertFalse($ua->isiOS()); 
        $this->assertFalse($ua->isiPad()); 
        $this->assertFalse($ua->isiPhone()); 
        $this->assertFalse($ua->isiPhone1()); 
        $this->assertFalse($ua->isiPhone2()); 
        $this->assertFalse($ua->isiPhone3()); 
        $this->assertFalse($ua->isiPhone4()); 
        $this->assertFalse($ua->isiPhone5()); 
        $this->assertFalse($ua->isLinux()); 
        $this->assertFalse($ua->isMTK());  
        $this->assertFalse($ua->isS60()); 
        $this->assertFalse($ua->isS60V1()); 
        $this->assertFalse($ua->isS60V2()); 
        $this->assertFalse($ua->isS60V3()); 
        $this->assertFalse($ua->isS60V5()); 
        $this->assertFalse($ua->isSymbian()); 
        $this->assertFalse($ua->isSymbian3()); 
        $this->assertFalse($ua->isWindows()); 
        $this->assertFalse($ua->isWP()); 
        $this->assertFalse($ua->isWinPad()); 
        $this->assertFalse($ua->isSupperHtml5()); 
        $this->assertFalse($ua->isWebKit()); 
        
        //test X-UCBrowser-UA
        $this->assertTrue($ua->isProxyMode()); 
        $this->assertFalse($ua->isNightMode()); 
        $this->assertTrue($ua->isNoImageMode()); 
        $this->assertFalse($ua->browingViewIsAdaptScreen()); 
        $this->assertTrue($ua->browingViewIsZoom()); 
        $this->assertFalse($ua->screenRotationFollowSystem()); 
        $this->assertTrue($ua->screenRotationLockVertical()); 
        $this->assertFalse($ua->screenRotationLockHorizontal()); 
        
        $this->assertEqual("320*240", $ua->getPixel());
        $this->assertEqual("320*240", $ua->getDensity());
        //error_log($ua->toString());
    }
}

?>
